home *** CD-ROM | disk | FTP | other *** search
/ APC & TCP 4 / APC & TCP 4.iso / games / publicdomain / a / asteroids2 / rotx / rot.c < prev    next >
C/C++ Source or Header  |  1995-07-20  |  8KB  |  446 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <intuition/intuition.h>
  4. #include <graphics/gfx.h>
  5. #include <graphics/gfxbase.h>
  6. #include <graphics/gfxmacros.h>
  7. #include <graphics/gels.h>
  8. #include <graphics/gfxbase.h>
  9. #include <graphics/rastport.h>
  10. #include <stdio.h>
  11. #include <h/rot.h>
  12. #include <h/define.h>
  13.  
  14. struct imagedata id[800];
  15. struct vectordata v[40];
  16. struct imagelocation il;
  17. struct drawlist dl[400];
  18.  
  19. struct gameinfo gi;
  20. struct control control;
  21. struct gameinput in;
  22.  
  23. struct ship ship[7];
  24. struct asteroid a[256];
  25. struct explosion e[32];
  26. struct fighter f[200];
  27. struct saucer saucer;
  28. struct box b[40];
  29. struct battleship bs[5];
  30. struct mine m[40];
  31. struct highscorelist hsl[20];
  32. struct saveoptions so;
  33. struct debris d[100];
  34. struct hyper h[100];
  35. struct keys k;
  36.  
  37. extern struct TextFont *basicfont;
  38. extern struct TextFont *hiresfont;
  39. extern struct TextFont *fixplain7font;
  40. extern struct RastPort *rp1[2];
  41. extern struct Screen *screen;
  42. extern struct Window *masterwindow;
  43.  
  44. struct NewWindow newpausewindow =
  45. {
  46. 270,200,160,50,0,0,RAWKEY,
  47. NOCAREREFRESH | ACTIVATE | BORDERLESS,
  48. NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  49. CUSTOMSCREEN
  50. };
  51.  
  52.  
  53. BYTE VxINC[32] = { 0,20,38,56,71,83,92,98,100,98,92,83,71,56,38,20,0,-20,-38,-56,-71,-83,-92,-98,-100,-98,-92,-83,-71,-56,-38,-20 };
  54. BYTE VyINC[32] = { -100,-98,-92,-83,-71,-56,-38,-20,0,20,38,56,71,83,92,98,100,98,92,83,71,56,38,20,0,-20,-38,-56,-71,-83,-92,-98 };
  55.  
  56. UBYTE bit;
  57.  
  58. main()
  59. {
  60. LONG x;
  61.  
  62. OpenLibraries();
  63. GetDefaults();
  64. LoadOptions();
  65. SetGameScreen();
  66. SetGameFont();
  67. LoadKeyDefines();
  68. Initialization();
  69.  
  70. for (;;)
  71.     {
  72.     bit=1;
  73.  
  74.     for(x=0;x<control.maxplayernum;x++)
  75.         {
  76.         control.shield[x]=200;
  77.         control.score[x] = 0;
  78.         control.tech[x] = 0;
  79.         control.lives[x] = 3;
  80.         control.weapon[x] = 0;
  81.         control.fire[x] = 0;
  82.         control.hyper[x] = 0;
  83.         control.firecount[x] = 0;
  84.         }
  85.     control.endgamewait = 0;
  86.     control.endgame = FALSE;
  87.     control.enemynum = 0;
  88.     for (x=0;x<control.playernum;x++)
  89.         control.player[x]=TRUE;
  90.  
  91.     ClearScreen();
  92.     changeview(0);
  93.     WaitStart();
  94.  
  95.     ClearScreen();
  96.     DrawGameScreen();
  97.     control.level = control.startlevel;
  98.     StartGame();
  99.     }
  100. }
  101.  
  102.  
  103.  
  104. ReplaceShip(n)
  105. LONG n;
  106. {
  107. LONG x;
  108.  
  109. if (control.lives[n] == 0)
  110.     {
  111.     if (control.endgame == FALSE)
  112.         {
  113.         control.player[n] = FALSE;
  114.  
  115.         control.endgame = TRUE;
  116.         for(x=0;x<control.playernum;x++)
  117.             if (control.player[x] == TRUE)
  118.                 {
  119.                 control.endgame = FALSE;
  120.                 }
  121.         if (control.endgame == TRUE) control.endgamewait = 60;
  122.         }
  123.     }
  124. else
  125. if (--control.wait[n] < 0)
  126.     if ((CheckAsteroidWindow(n) == TRUE) ||
  127.        ((in.FI[0] == TRUE) && (control.input[n] == 0)) || ((in.FI[1] == TRUE) && (control.input[n] == 1)))
  128.             {
  129.             initPlayer(n);
  130.             control.wait[n] = 30;
  131.             IncreaseShields(n,0);
  132.             IncreaseLives(n,-1);
  133.             initInput(n);
  134.             }
  135. }
  136.  
  137.  
  138.  
  139. StartGame()
  140. {
  141. LONG x;
  142.  
  143. for (;;)                /*  main loop  */
  144. {
  145. if (control.endgame == FALSE)
  146.     {
  147.     makesound(10,3);
  148.     initLEVEL();
  149.     DisplayLevel();
  150.     for(x=0;x<2;x++) initInput(x);
  151.     AsteroidLoop();
  152.  
  153.     if (control.endgame == FALSE)    control.level++;
  154.     }
  155. else
  156.     {
  157.     for(x=0;x<control.playernum;x++)
  158.         if (control.score[x] > hsl[19].score)
  159.             {
  160.             ClearScreen();
  161.             changeview(0);
  162.             dohighscorelist(x);
  163.             }
  164.     return;
  165.     }
  166. }
  167. }
  168.  
  169.  
  170.  
  171. AsteroidLoop()
  172. {
  173. LONG x,anum=1;
  174. LONG random;
  175.  
  176.  
  177. #if REGISTERED == FALSE
  178. if ((control.game == 0) && (control.level > 1+1+1+1+1))
  179.     {
  180.     control.endgame = TRUE;
  181.     for(x=0;x<control.playernum;x++)
  182.         {
  183.         control.lives[x] = 0;
  184.         ship[x].pilot = DESTROYED;
  185.         }
  186.     }
  187. #endif
  188.  
  189.  
  190. while(anum > 0)
  191. {
  192. bit^=1;
  193.  
  194. getjoystickinput();
  195.  
  196. random = Random(1000.0);
  197. if ((random > 996-control.level) && (saucer.flag == FALSE)) initsaucer();
  198.  
  199. if (control.game != 1)
  200.     {
  201.     if (control.fighter == FALSE)
  202.         for(x=0;x<control.playernum;x++)
  203.             if ((ship[x].shield < 50) && (ship[x].pilot != DESTROYED))
  204.                 {
  205.                 initfighters();
  206.                 break;
  207.                 }
  208.  
  209.     random = Random(1000.0);
  210.     if ((random > (997-control.level)) && (control.enemynum < control.enemyonscreen))
  211.         addenemy();
  212.     }
  213.  
  214.  
  215. for(x=0;x<control.playernum;x++)
  216.     if ((ship[x].pilot == DESTROYED) && (control.player[x] == TRUE) && (control.hyper[x] == 0))
  217.         ReplaceShip(x);
  218.  
  219.  
  220. if (control.endgame == TRUE)
  221.     {
  222.     printendgame();
  223.     control.endgamewait--;
  224.     if ((control.endgamewait <= 0) && 
  225.        ((control.score[0] > hsl[19].score) || (control.score[1] > hsl[19].score)))
  226.         return;
  227.     }
  228.  
  229.  
  230. for(x=0;x<control.playernum;x++)
  231.     {
  232.     if ((ship[x].pilot != DESTROYED) && (control.player[x] == TRUE))
  233.         HandleInput(x,control.input[x]);
  234.     }
  235.  
  236. if (in.FI[0] == TRUE) in.FI[0] = FALSE;
  237. if (in.FI[1] == TRUE) in.FI[1] = FALSE;
  238.  
  239. if (in.EXIT == TRUE)
  240.     {
  241.     control.endgame = TRUE;
  242.     return;
  243.     }
  244. if ((in.PAUSE == TRUE) && (bit == 1)) handlePause();
  245.  
  246.  
  247. for (x=0;x<control.playernum;x++)
  248.     {
  249.     if (control.hyper[x] > 0)
  250.         {
  251.         if (--control.hyper[x] == 0) ship[x].pilot = HUMAN;
  252.         }
  253.     else UpdatePlayer(x);
  254.     }
  255.  
  256. for (x=control.playernum;x<control.playernum+control.maxenemynum;x++)
  257.     {
  258.     if (--ship[x].wait < 0) ship[x].wait = 0;
  259.  
  260.     if (ship[x].image == il.minelayer) UpdateMineLayer(x);
  261.     else
  262.     if (ship[x].image == il.magnetic) UpdateMCruiser(x);
  263.     else
  264.     if (ship[x].image == il.xcruiser) UpdateXCruiser(x);
  265.     else
  266.     if (ship[x].image == il.dreadnought) UpdateDreadnought(x);
  267.     else                              UpdateCruiser(x);
  268.     }
  269.  
  270. for (x=0;x<control.maxenemynum+control.playernum;x++)
  271.     {
  272.     DrawFire(x);
  273.     DrawShield(x);
  274.     if (ship[x].image != il.dreadnought) DrawPhoton(x);
  275.     else                              DrawExpander(x);
  276.     }
  277. DrawSaucerFire();
  278.  
  279. if (saucer.flag != FALSE)
  280.     {
  281.     UpdateSaucer();
  282.     if (saucer.type == 1)
  283.         {
  284.         if ((Random(1000.0) > 960-20*control.level) && (saucer.haltfire == FALSE))
  285.             InitSmartSaucerFire();
  286.         }
  287.     else
  288.     if ((Random(1000.0) > 900-20*control.level) && (saucer.haltfire == FALSE))
  289.         InitSaucerFire();
  290.  
  291.     if (--saucer.delay == 0) ChangeSaucerCourse();
  292.     }
  293.  
  294.  
  295. DrawThrust();
  296. UpdateFighters(x);
  297. DrawFighterFire(x);
  298. DrawTokenExplosions();
  299. UpdateBoxes();
  300. UpdateMines();
  301. UpdateDebris();
  302. UpdateHyper();
  303.  
  304. control.asize=anum = 0;
  305. for (x=0;x<control.asteroidnum;x++)
  306.     if (a[x].flag != FALSE)
  307.         {
  308.         anum++;
  309.         control.asize+=(3-a[x].size);
  310.         UpdateAsteroid(x);
  311.         }
  312.  
  313.  
  314. dodrawlist();
  315.  
  316.  
  317. waitfortimer();
  318. timedelay(control.delay);
  319. WaitBlit();
  320. changeview(bit);
  321.  
  322.  
  323.  
  324. SetAPen(rp1[1-bit],0);
  325.  
  326. EraseAll();
  327. EraseSaucer();
  328. EraseFighterFire();
  329. EraseFighters();
  330. EraseMines();
  331. EraseDebris();
  332. EraseHyper();
  333. EraseAsteroids();
  334. EraseTokenExplosions();
  335. EraseBoxes();
  336. EraseSaucerFire();
  337. for (x=0;x<control.maxenemynum+control.playernum;x++)
  338.     {
  339.     EraseFire(x);
  340.     EraseShield(x);
  341.     ErasePhoton(x);
  342.     if (ship[x].image == il.dreadnought) EraseDisplacer(x);
  343.     }
  344. RectFill(rp1[1-bit],579,2,620,11);
  345. }
  346. }
  347.  
  348.  
  349.  
  350. todrawlist(pic,xx,yy,mask,color)
  351. WORD pic,xx,yy;
  352. UWORD mask;
  353. BYTE color;
  354. {
  355.  
  356. dl[control.dlpos].x = xx;
  357. dl[control.dlpos].y = yy;
  358. dl[control.dlpos].pic = pic;
  359. dl[control.dlpos].color = color;
  360. dl[control.dlpos].mask = mask;
  361. control.dlpos++;
  362. }
  363.  
  364.  
  365. dodrawlist()
  366. {
  367. LONG x;
  368.  
  369.  
  370. SetAPen(rp1[bit],3);
  371. for(x=0;x<control.dlpos;x++)
  372.     {
  373.     SetWrMsk(rp1[bit],dl[x].mask);
  374.     BltTemplate(id[dl[x].pic].data,0,2*id[dl[x].pic].wo,rp1[bit],
  375.               dl[x].x,dl[x].y,id[dl[x].pic].wi,id[dl[x].pic].he);
  376.     }
  377.  
  378. control.dlpos = 0;
  379. }
  380.  
  381.  
  382.  
  383. handlePause()
  384. {
  385. struct RastPort *wrp;
  386. struct Window *window;
  387. struct IntuiMessage *message;
  388. ULONG pwinsig,mwinsig,signal;
  389.  
  390. newpausewindow.LeftEdge = gi.wi/2-90;
  391. newpausewindow.TopEdge = gi.he/2-20;
  392. newpausewindow.Screen = screen;
  393. window = (struct Window *)OpenWindow(&newpausewindow);
  394. if (window == NULL) printf("open window error\n");
  395.  
  396. wrp = window->RPort;
  397.  
  398. SetAPen(wrp,1);
  399. SetFont(wrp,fixplain7font);
  400.  
  401. Move(wrp,13,30);
  402. Text(wrp,"GAME PAUSED",11);
  403.  
  404. pwinsig = 1L << window->UserPort->mp_SigBit;
  405. mwinsig = 1L << masterwindow->UserPort->mp_SigBit;
  406.  
  407. while(message = (struct IntuiMessage *)GetMsg(window->UserPort)) ReplyMsg((struct Message *)message);
  408. while(message = (struct IntuiMessage *)GetMsg(masterwindow->UserPort)) ReplyMsg((struct Message *)message);
  409.  
  410. for(;;)
  411. {
  412. signal = Wait(pwinsig | mwinsig);
  413.  
  414. if (signal & pwinsig)
  415.     {
  416.     while (message = (struct IntuiMessage *)GetMsg(window->UserPort))
  417.         {
  418.         ReplyMsg((struct Message *)message);
  419.  
  420.         if (message->Code < 0x64)
  421.             {
  422.             CloseWindow(window);
  423.             in.PAUSE = FALSE;
  424.             return;
  425.             }
  426.         }
  427.     }
  428. else
  429. if (signal & mwinsig)
  430.     {
  431.     while (mes